/*
 * ScenarioImpl.java
 * 
 * Created on 21.05.2007, 18:58:39
 */

package logrus.beanmock.scenario;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

import logrus.beanmock.invoker.MethodInvocationInfo;
import logrus.beanmock.invoker.MethodInvoker;
import logrus.beanmock.invoker.ScenarioMethodInvoker;

/**
 * @author serge
 */
public class ScenarioImpl implements  Scenario {
    
    private List<MethodInvocationInfo> infos;

    public ScenarioImpl(MethodInvocationInfo... infos) {
        this.infos = Arrays.asList(infos);
    }

    public MethodInvoker getMethodInvoker(String... scenarios) {
        List<MethodInvocationInfo> activeInfos = new LinkedList<MethodInvocationInfo>();
        for (String scenario : scenarios) {
            for (MethodInvocationInfo info : infos) {
                if (info.getScenario().equals(scenario)) {
                    activeInfos.add(info);
                }
            }
        }
        return new ScenarioMethodInvoker(activeInfos.toArray(EMPTY_ARRAY));
    }
    
    private final static MethodInvocationInfo[] EMPTY_ARRAY = new MethodInvocationInfo[0];

}
